package com.sykuku.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sykuku.common.R;
import com.sykuku.dto.OrderPageConditionDto;
import com.sykuku.pojo.Orders;
import com.sykuku.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/order")

public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 用户下单
     * @param orders
     * @return
     */
    @PostMapping("submit")
    public R<String> submit(@RequestBody Orders orders){
        log.info("订单数据：{}",orders);
        orderService.submit(orders);
        return R.success("下单成功");
    }

    @GetMapping("/page")
    public R<Page<Orders>> page(OrderPageConditionDto dto){
        Page<Orders> ordersPage = orderService.orderSelecetPage(dto);
        return R.success(ordersPage);
    }

    @GetMapping("/userPage")
    public R<Page<Orders>> orders (Integer page,Integer pageSize){

        Page<Orders> ordersPage = new Page<>(page,pageSize);

         orderService.page(ordersPage);

        return R.success(ordersPage);

    };
}
